<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta content="webkit" name="renderer">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
    <link href="/URMS/lib/layui-v2.5.5/css/layui.css" media="all" rel="stylesheet">
    <link href="/URMS/css/public.css" media="all" rel="stylesheet">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body style="align-content:  center;">
<form action="" class="layui-form layuimini-form" style="text-align: center;width: 800px">

    <div class="layui-form-item">
        <label class="layui-form-label required">账号</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-reqtext="账号不能为空" lay-verify="required" name="account" placeholder="请输入账号"
                   type="text">
            <tip>填写自己管理账号的名称。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">

            <input class="layui-input" lay-reqtext="用户名不能为空" lay-verify="required" name="name" placeholder="请输入用户名"
                   type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-reqtext="密码不能为空" lay-verify="required" name="password" placeholder="请输入密码"
                   type="password">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">再次输入密码</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-reqtext="密码不能为空" lay-verify="required" name="password2" placeholder="请输入密码"
                   type="password">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input lay-skin="switch" lay-text="可用|禁用" name="status" type="checkbox">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-filter="saveBtn" lay-submit>确认保存</button>
        </div>
    </div>
</form>
<script charset="utf-8" src="/URMS/lib/layui-v2.5.5/layui.js"></script>
<script charset="utf-8" src="/URMS/js/lay-config.js?v=1.0.4"></script>
<script>
    layui.use(['form'], function () {
        let form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let index = (function () {
                let user = data.field
                confirm(data.field.name)
                if (user.name == '') {
                    layer.msg('用户名不能为空');
                    return false;
                }

                $.ajax({
                    url: "/URMS/sysUser/addUserSubmit",
                    data: user,
                    async: false,
                    type: "POST",
                    error: function (XMLHttpResponse) {
                        layer.msg("添加出错");
                    },
                    success: function (data) {
                        if (false == data) {
                            layer.msg("添加失败");

                        } else {
                            layer.msg("添加成功");
                        }
                    }
                })

                // 关闭弹出层
                layer.close(index);

                let iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);

            });
        })
    });
</script>
</body>
</html>